package 力扣日常刷题.木22二月.第21天227;

/**
 * @author 帅小伙
 * @date 2022/2/27
 * @description 后一个字符串是对前一个字符串的描述
 */
public class Demo175外观数列 {

    public static void main(String[] args) {
        countAndSay(4);
    }

    public static String countAndSay(int n) {
        String ans = "1";
        for (int i = 2; i <= n; i++) {
            String cur = "";
            int m = ans.length();
            for (int j = 0; j < m; ) {
                int k = j + 1;
                while (k < m && ans.charAt(j) == ans.charAt(k)) k++;
                int cnt = k - j;
                cur += cnt + "" + ans.charAt(j);
                j = k;
            }
            ans = cur;
        }
        return ans;
    }

}
